package com.pj.wisdomlogistics.ui.adapter;


import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;

import com.pj.wisdomlogistics.R;
import com.pj.wisdomlogistics.entity.MeetingSimpleInfo;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseAdapter;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseViewHolder;
import com.zhy.autolayout.utils.AutoUtils;

public class MeetingSimpleAdapter extends BaseAdapter<MeetingSimpleInfo, BaseViewHolder> {
    private Drawable drawableCountEmpty;


    public MeetingSimpleAdapter(Context context) {
        super(context);
        drawableCountEmpty = context.getResources().getDrawable(R.drawable.number_grey);
        drawableCountEmpty.setBounds(0, 0, drawableCountEmpty.getMinimumWidth(), drawableCountEmpty.getMinimumHeight());
    }

    @Override
    public BaseViewHolder createCustomViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(parent, R.layout.item_choose_meeting);
    }

    @Override
    public void bindCustomViewHolder(BaseViewHolder viewHolder, int position) {
        AutoUtils.autoSize(viewHolder.itemView);

        final MeetingSimpleInfo item = getItem(position);

        viewHolder.getTextView(R.id.tv_meeting_title).setText(item.getMeetingName());
        viewHolder.getTextView(R.id.tv_meeting_count).setText(item.getMeetingContent() + "人");

        viewHolder.getTextView(R.id.tv_meeting_count).setCompoundDrawables(drawableCountEmpty, null, null, null);
        viewHolder.getView(R.id.iv_meeting).setBackgroundResource(
                item.getMeetingName().contains("礼堂") ? R.drawable.c_litang :
                    item.getMeetingName().contains("多媒体") ? R.drawable.c_duomeiti : R.drawable.c_huiyishi);

        viewHolder.getView(R.id.rel_choose_meeting).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClick.itemClick(item.getMeetingRoomID() , item);
            }
        });
    }

    @Override
    public int getCustomViewType(int position) {
        return 0;
    }


    public onItemClick mOnItemClick;

    public interface onItemClick {
        public void itemClick(int id , MeetingSimpleInfo mInfo);
    }

    public void setListener(onItemClick mListener) {
        this.mOnItemClick = mListener;
    }

}
